//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_CL_QUEUE_H
#define _UX_CL_QUEUE_H

#include "CLDevice.h"
#include "CLEvent.h"

namespace Engine
{
namespace CLSystems
{


	//
	// CL Queue
	//

	class _EXPORT_ CLQueue : public CLBaseObject
	{
	public:
		struct TCLMem
		{
			CLMemory	*pMem;
			void		*pPtr;
			///
			TCLMem(): pMem(nullptr), pPtr(nullptr) {}
			TCLMem(CLMemory *mem, void *ptr): pMem(mem), pPtr(ptr) {}
		};

		typedef array< TCLMem >		mem_obj_array_t;

	protected:
		cl_command_queue	_pQueue;
		
	protected:
		virtual void _RetainRef()	const;
		virtual void _ReleaseRef()	const;
		virtual uint _GetRefCount()	const;
		virtual void _Destroy();

	public:
		CLQueue();
		~CLQueue();

		bool Create(cl_queue_property::type eFlags);
		virtual void Destroy();

		bool Flush() const;
		bool Finish() const;
		bool EnqueueBarrier() const;
		bool EnqueueWait(const cl_event_array_t &aEvents) const;
		bool EnqueueMarker(CLEvent *&pEvent) const;

		bool EnqueueNativeKernel(void (*pUserFunc)(void *), void *pArgs, usize uArgsSize, const mem_obj_array_t &aMemList,
						const cl_event_array_t &aEvents = cl_event_array_t(), CLEvent **pEvent = nullptr) const;

		bool EnqueueAcquireGLObjects(const cl_mem_array_t &aMemList,
						const cl_event_array_t &aEvents = cl_event_array_t(), CLEvent **pEvent = nullptr) const;

		bool EnqueueReleaseGLObjects(const cl_mem_array_t &aMemList,
						const cl_event_array_t &aEvents = cl_event_array_t(), CLEvent **pEvent = nullptr) const;

		cl_command_queue	GetIdent()		const	{ return _pQueue; }
	};

//-------------------------------------------------------------------

}	// CLSystems
}	// Engine

#endif	// _UX_CL_QUEUE_H